package at.chl.springbox;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import at.chl.springbox.runner.ISpringBoxRunner;

public class SpringBox implements ISpringBox{
	private AbstractApplicationContext context;
	public SpringBox(AbstractApplicationContext context) {
		this.context=context;
	}
	
	public AbstractApplicationContext getContext() {
		return context;
	}

	public static SpringBox getInstance(String classPathContext){
		ClassPathXmlApplicationContext theContext=new ClassPathXmlApplicationContext(classPathContext);
		
		return new SpringBox(theContext);
	}

	@Override
	public void startBox() {
		
		prepareBox();
		
		runBox();
		
		closeBox();
		
	}

	private void closeBox() {
		// TODO implement logic to close the box
		
	}

	private void runBox() {
		ISpringBoxRunner runner=(ISpringBoxRunner)context.getBean("springBoxRunner");
		
		if(runner==null){
			//EXC
		}
		runner.run();
	}

	private void prepareBox() {
		// TODO implement logic to prepare box for running the application
		
	}
}
